﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://wubiyu.cnblogs.com">
<head>
      <title></title>
      <link href="../../Theme/DomExtGray/gray.min.css" rel="Stylesheet" type="text/css" />
      <link href="PageModel.css" rel="Stylesheet" type="text/css" />
      <script type="text/javascript" src="../../domExt.min.js"></script>
</head>
<body>
      <div class="fun_title">
            _h.GetDataFromTemplet(str, rowsIndex, dataSource);
      </div>
      <div class="fun_content">
            描述： 将数据源中对应的值填入模板中。数据源只能是一个二维数组或者一维对象数组。<br />
            <div class="fun_title2">
                  参数:
            </div>
            <div class="fun_content2">
                  str：含有模板参数的字符串：列如：&lt;a href=&quot;&quot;&gt;{=Name} l {=[0]} | CurrentIndex&lt;/a&gt;<br />
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 模板参可以是对象，数组，和系统预定义的值。<br />
                  rowsIndex：获取数据源中的第几行的数据。<br />
                  dataSource：数据源只能是一个二维数组或者一维对象数组。<br />
                  <strong>Retrun:</strong><br />
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 字符串<br />
                  <br />
            </div>
            <div class="fun_title2">
                  示例:
            </div>
            <div class="code">
                  &lt;script type=&quot;text/javascript&quot;&gt;<br />
                  &nbsp;&nbsp;&nbsp; var dataSource = [[1,&quot;成都&quot;],[1,&quot;上海&quot;],[1,&quot;北京&quot;]];<br />
                  &nbsp;&nbsp;&nbsp; var str = &quot;&lt;a href=&#39;&#39;&gt;{=[1]} and 
                  {=CurrentIndex}&lt;/a&gt;&quot;;<br />
                  &nbsp;&nbsp;&nbsp; alert(_h.GetDataFromTemplet(str,0,dataSource));&nbsp;<br />
                  &nbsp;&nbsp;&nbsp; alert(_h.GetDataFromTemplet(str,1,dataSource));<br />
                  &nbsp;&nbsp;&nbsp; alert(_h.GetDataFromTemplet(str,2,dataSource));<br />
&nbsp;&nbsp;&nbsp; dataSource=[{id:1,name:&#39;chengdu&#39;},{id:2,name:&#39;shanghai&#39;},{id:3,name:&#39;BJ&#39;}];<br />
&nbsp;&nbsp;&nbsp; str = &quot;&lt;a href=&#39;&#39;&gt;{=name} and {=CurrentIndex}&lt;/a&gt;&quot;;<br />
&nbsp;&nbsp;&nbsp; alert(_h.GetDataFromTemplet(str,0,dataSource));&nbsp;<br />
                  &nbsp;&nbsp;&nbsp; alert(_h.GetDataFromTemplet(str,1,dataSource));<br />
                  &nbsp;&nbsp;&nbsp; alert(_h.GetDataFromTemplet(str,2,dataSource));<br />
                  &lt;/script&gt;</div>
            <input type="hidden" value=" var div1 = _g('#div1');  var collObjects1=_g('div');var collObjects2=_g('.testclass',div1);alert(div1.innerHTML);"
                  id="jscode">
            <br />
            <h:btn onclick="run_click();">执行脚本</h:btn>
            <div id="htmltemp" style="display: none;">
            </div>
            <script type="text/javascript">
            function run_click() {
                  var dataSource = [[1, "成都"], [1, "上海"], [1, "北京"]];
                  var str = "<a href=''>{=[1]} and {=CurrentIndex}</a>";
                  alert(_h.GetDataFromTemplet(str, 0, dataSource));
                  alert(_h.GetDataFromTemplet(str, 1, dataSource));
                  alert(_h.GetDataFromTemplet(str, 2, dataSource));
                  dataSource = [{ id: 1, name: 'chengdu' }, { id: 2, name: 'shanghai' }, { id: 3, name: 'BJ'}];
                  str = "<a href=''>{=name} and {=CurrentIndex}</a>";
                  alert(_h.GetDataFromTemplet(str, 0, dataSource));
                  alert(_h.GetDataFromTemplet(str, 1, dataSource));
                  alert(_h.GetDataFromTemplet(str, 2, dataSource));
            }
            </script>
</body>
</html>
